import time

# with open('file') as f:
#     w = f.read()
#     print(type(w))

#
# t = time.time()
# print(int(t))
# return int(t)

# 高阶函数
# def bar():
#     time.sleep(3)
#     print('aaaaaaaaaaa')
#
# def test(func):
#     start_time = time.time()
#     func()
#     end_time = time.time()
#     print('运行时间是%d' % (end_time-start_time))
# test(bar)

#返回一个函数的demo
# def bar():
#     time.sleep(3)
#     print('aaaaaaaaaaa')
#
# def test1(func):
#     print(func)
#     return func
# bar = test1(bar)
#
# bar()

#嵌套函数
# def foo():
#     print('in the foo')
#     def bar():
#         print('in the bar')
#
#     bar()
# foo()

#装饰器
# def timer(func):
#     def deco(*args, **kwargs):
#         start_time = time.time()
#         return func(*args, **kwargs)
#         stop_time = time.time()
#         print('运行时间是%d秒' % (stop_time-start_time))
#     return deco
#
# @timer  #test1=timer(test1)
# def test1():
#     time.sleep(3)
#     print('in the test1')
# test1()

#装饰器例子，登录功能,很难理解
user_name,pass_word = 'liuqi','123456'
def auth(auth_type):
    print('auth_type=',auth_type)
    def out_wrapper(func):
        def wrapper(*args, **kwargs):
            print('wrapper func args', *args, **kwargs)
            username = input('请输入账号').strip()
            passwor = input('请输入密码').strip()
            if auth_type == 'local':
                if username == user_name and passwor == pass_word:
                    print('登录成功')
                    return func(*args, **kwargs)
                else:
                    print('登录失败')
                    exit()
            else:
                print('杀杀杀杀杀杀杀杀杀')
        return wrapper
    return out_wrapper

def index():
    print('welcome to index page')
@auth(auth_type='local')
def home():
    print('welcome to home page')
    return 'from home'
@auth(auth_type='ssh')
def bbs():
    print('welcome to bbs page')

index()
print(home())
bbs()